﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace ViewMaker.Core.Controls
{
    /// <summary>
    /// データグリッド チェックボックス列
    /// </summary>
    public class DataGridCheckBoxColumnViewElement : DataGridColumnViewElement
    {
        public new class Properties : DataGridColumnViewElement.Properties
        {
            public const string IsThreeState = "IsThreeState";
        }

        /// <summary>
        /// ３値形式のチェックボックス
        /// </summary>
        public bool? IsThreeState { get; set; }

        public DataGridCheckBoxColumnViewElement()
        {
            ControlType = ViewControlType.DataGridCheckBoxColumn;
        }

        public override List<XamlNode> CreateXaml(XamlNode parent)
        {
            var list = new List<XamlNode>();
#if !SILVERLIGHT
            var col = parent.CreateElement("DataGridCheckBoxColumn");
#else
            var col = parent.CreateElement("sdk", "http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk", "DataGridCheckBoxColumn");
#endif
            if (!string.IsNullOrEmpty(Item.BindPath))
            {
                SetBindingAttribute(col, "Binding", Item.BindPath, Item.IsOneWay);
            }
#if SILVERLIGHT
            else
            {
                //バインドを空にするとエラーになるため回避策
                SetBindingAttribute(col, "Binding", "__dummy__", Item.IsOneWay);
            }
#endif
            if (IsThreeState.HasValue) col.SetAttribute("IsThreeState", IsThreeState.ToString());

            ApplyBaseProperty(col);
            list.Add(col);
            return list;
        }

    }
}
